from rest_framework import serializers
from doctor.models import TitleModel, MajorModel, DepartmentModel, SubMajorModel, DoctorModel,StatusModel,RemoteConsultationModel,RemoteConsultationModel1


class TitleSerializer(serializers.ModelSerializer):
    class Meta:
        model = TitleModel
        fields = '__all__'


class MajorSerializer(serializers.ModelSerializer):
    class Meta:
        model = MajorModel
        fields = '__all__'


class DepartmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = DepartmentModel
        fields = '__all__'


class SubMajorSerializer(serializers.ModelSerializer):
    class Meta:
        model = SubMajorModel
        fields = '__all__'


class DoctorSerializer(serializers.ModelSerializer):
    avatar = serializers.ImageField(required=False)

    new_title = serializers.SerializerMethodField(read_only=True)
    new_major = serializers.SerializerMethodField(read_only=True)
    new_department = serializers.SerializerMethodField(read_only=True)
    new_submajor = serializers.SerializerMethodField(read_only=True)

    def get_new_title(self, obj):
        return obj.title.tname

    def get_new_major(self, obj):
        return obj.major.mname

    def get_new_department(self, obj):
        return obj.department.dname

    def get_new_submajor(self, obj):
        return obj.sub_major.sname

    class Meta:
        model = DoctorModel
        fields = '__all__'



class StatusSerializer(serializers.ModelSerializer):
    class Meta:
        model = StatusModel

        fields = '__all__'


class RemoteConsultationSerializer(serializers.ModelSerializer):
    avatar = serializers.ImageField(required=False)

    new_major = serializers.SerializerMethodField(read_only=True)
    new_title = serializers.SerializerMethodField(read_only=True)
    consultation_status=serializers.SerializerMethodField(read_only=True)
    def get_new_major(self, obj):
        return obj.major.mname

    def get_new_title(self, obj):
        return obj.title.tname
    def get_consultation_status(self, obj):
        return obj.consultation_status.sname

    class Meta:
        model = RemoteConsultationModel
        fields = '__all__'




class RemoteConsultationModelSerializer1(serializers.ModelSerializer):
    class Meta:
        model = RemoteConsultationModel1
        fields = '__all__'


class RemoteConsultationModelSerializer2(serializers.ModelSerializer):
    remoteConsultationModel=RemoteConsultationSerializer()
    class Meta:
        model = RemoteConsultationModel1
        fields = '__all__'



